
package com.oly.cms.user.controller.common;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.oly.cms.general.service.taglib.CommonTag;
import com.oly.cms.user.security.service.WebRegisterService;
import com.grace.common.core.controller.BaseController;
import com.grace.common.core.domain.AjaxResult;
import com.grace.common.core.domain.model.RegisterBody;
import com.grace.common.enums.SysConfigGroups;
import com.grace.common.utils.SecurityUtils;
import com.grace.common.utils.StringUtils;
import com.grace.system.service.impl.SysSearchConfigServiceImpl;

/*
 * @Author: zhige 634866553@qq.com
 * @Date: 2024-03-27 17:26:22
 * @LastEditors: zhige 634866553@qq.com
 * @LastEditTime: 2024-03-27 17:38:46
 * @Description: 用户登录注册相关
 * 
 */
@Controller
@RequestMapping
public class UserController extends BaseController {

    @Autowired
    private WebRegisterService registerService;

    @Autowired
    private SysSearchConfigServiceImpl configService;

    @Autowired
    private CommonTag commonTag;
     
    /**
     * 判断用户是否登录
     * @param themeName
     * @param userId
     * @return
     */
    @GetMapping("/{themeName}/user/isLogin/{userId}")
    public @ResponseBody AjaxResult isLogin(@PathVariable("themeName") String themeName,
            @PathVariable("userId") Long userId) {
        Long loginUserId = SecurityUtils.getUserId();
        if (loginUserId == null) {
            return AjaxResult.error("用户未登录");
        } else if (!loginUserId.equals(userId)) {
            return AjaxResult.error("登陆账号不符");
        } else
            return AjaxResult.success("身份验证成功");
    }

    /**
     * 用户查询
     * @param themeName
     * @param userName
     * @return
     */
    @GetMapping("/{themeName}/user/getUser/{userName}")
    public AjaxResult selectUser(@PathVariable("themeName") String themeName,
            @PathVariable("userName") String userName) {
        return AjaxResult.success(commonTag.getUserVo(userName));
    }

    /**
     * 用户登录
     * 系统内置登录页
     * 实际登录通过异步
     * @param forward
     * @param themeName
     * @param modelMap
     * @return
     */
    @GetMapping("/{themeName}/login")
    public String login(@RequestParam(required = false, defaultValue = "") String forward,
            @PathVariable("themeName") String themeName,
            ModelMap modelMap) {
        modelMap.put("forward", forward);
        modelMap.put("themeName", themeName);
        return "user/login";
    }

    

    /**
     * 用户个人中心
     * 
     * @param userId
     * @return
     */
    @GetMapping("/{themeName}/user/personal/{userId}")
    public String personal(@PathVariable("userId") Long userId) {
        return "user/personal";
    }

}
